import msg from "../../../utils/msg";
import { weeklyAbsentExport, weeklyAbsentPre } from "../../../utils/request/api";
import User from "../../../utils/user";

// pages/user/weekly/weekly.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:{} as {[key:number]:number},
    user:{grade:''} as User,
  },
  onClickLeft(){
    wx.navigateBack();
  },
  goToDetail(e:any){
    let week=e.currentTarget.dataset.week;
    wx.navigateTo({
      url:"./weeklyDetail/weeklyDetail?week="+week+'&count='+this.data.list[week],
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  exportOne:async function(e:any){
    let week = e.currentTarget.dataset.index;
    await msg.confirm('是否导出数据','');
    let user = this.data.user;
    msg.Loading('导出数据中');
    await weeklyAbsentExport({data:{openid:user.openid,week:week},fileName:user.grade+"级第"+week+"周缺勤名单"});
    msg.hideLoading();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow:async function() {
    var user = new User;
    msg.Loading('计算缺勤情况中')
    let data=await weeklyAbsentPre({openid:user.openid})
    .then((res:any)=>{
      return res.data.data;
    });
    this.setData({
      list:data.data,
      nowWeek:data.nowWeek,
      user:user,
    });
    msg.hideLoading();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})